/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.ec.shopping.entity.ApplyCampaign
   Module Description   :

   Date Created      : 2010/6/28
   Original Author   : jeffma
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.ec.shopping.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.yaodian100.ec.campaign.entity.Campaign;

/**
 * @author jeffma
 * 
 */
public class ApplyCampaign implements Serializable {

	/** serialVersionUID */
	private static final long serialVersionUID = -4261667795270837932L;
	/** campaign object */
	private Campaign campaign;
	/** isActive */
	private boolean isActive = false;
	/** applyProductIds */
	private List<String> applyProductIds;
	private Map<String, Double> redMap;// 裝紅標商品的資訊
	private Map<String, Double> greenMap;// 裝紅標商品的資訊
	private List<Map.Entry<String, Double>> redSortList;// 按單價以降序方式排序後的紅標商品資訊
	private List<Map.Entry<String, Double>> greenSortList;// 按單價以降序方式排序後的紅標商品資訊
	private boolean rgCategory = false;// 判斷是否有符合紅綠標活動
	private int redSumQty = 0;// 用來算符合紅標的商品數量
	private int greenSumQty = 0;// 用來算符合綠標的商品數量
	/** sumAmount */
	private BigDecimal sumAmount = BigDecimal.ZERO;
	/** sumQty */
	private int sumQty = 0;
	/** sumDiscount, 活動折扣總計 */
	private BigDecimal sumDiscount = BigDecimal.ZERO;

	/** freeProductId, 贈品(商品)代碼 */
	private String freeProductId;

	/** default constructor */
	public ApplyCampaign() {
		super();
	}

	/** default constructor */
	public ApplyCampaign(Campaign campaign) {
		super();
		this.campaign = campaign;
	}

	/**
	 * @return the campaign
	 */
	public Campaign getCampaign() {
		return campaign;
	}

	/**
	 * @param campaign the campaign to set
	 */
	public void setCampaign(Campaign campaign) {
		this.campaign = campaign;
	}

	/**
	 * @return the freeProductId
	 */
	public String getFreeProductId() {
		return freeProductId;
	}

	/**
	 * @param freeProductId the freeProductId to set
	 */
	public void setFreeProductId(String freeProductId) {
		this.freeProductId = freeProductId;
	}

	/**
	 * @return the isActive
	 */
	public boolean isActive() {
		return isActive;
	}

	/**
	 * @param isActive the isActive to set
	 */
	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}

	/**
	 * @return the applyProductIds
	 */
	public List<String> getApplyProductIds() {
		if (applyProductIds == null) {
			applyProductIds = new ArrayList();
		}
		return applyProductIds;
	}

	/**
	 * @param applyProductIds the applyProductIds to set
	 */
	public void setApplyProductIds(List<String> applyProductIds) {
		this.applyProductIds = applyProductIds;
	}

	/**
	 * @return the sumAmount
	 */
	public BigDecimal getSumAmount() {
		return sumAmount;
	}

	/**
	 * @param sumAmount the sumAmount to set
	 */
	public void setSumAmount(BigDecimal sumAmount) {
		this.sumAmount = sumAmount;
	}

	/**
	 * @return the sumQty
	 */
	public int getSumQty() {
		return sumQty;
	}

	/**
	 * @param sumQty the sumQty to set
	 */
	public void setSumQty(int sumQty) {
		this.sumQty = sumQty;
	}

	/**
	 * @return the sumDiscount
	 */
	public BigDecimal getSumDiscount() {
		return sumDiscount;
	}

	/**
	 * @param sumDiscount the sumDiscount to set
	 */
	public void setSumDiscount(BigDecimal sumDiscount) {
		this.sumDiscount = sumDiscount;
	}

	public Map<String, Double> getRedMap() {
		if (redMap == null) {
			redMap = new TreeMap<String, Double>();
		}
		return redMap;
	}

	public void setRedMap(Map<String, Double> redMap) {
		this.redMap = redMap;
	}

	public Map<String, Double> getGreenMap() {
		if (greenMap == null) {
			greenMap = new TreeMap<String, Double>();
		}
		return greenMap;
	}

	public void setGreenMap(Map<String, Double> greenMap) {
		this.greenMap = greenMap;
	}

	// 將紅標的map,按value(也就是uniprice)作降序
	public List<Map.Entry<String, Double>> getRedSortList() {
		if (getRedMap().size() > 0) {
			redSortList = new ArrayList<Map.Entry<String, Double>>(getRedMap().entrySet());
			Collections.sort(redSortList, new Comparator<Map.Entry<String, Double>>() {
				public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) {
					return (int) (o2.getValue() - o1.getValue());
				}
			});
		}
		return redSortList;
	}

	// 將綠標的map,按value(也就是uniprice)作降序
	public List<Map.Entry<String, Double>> getGreenSortList() {
		if (getGreenMap().size() > 0) {
			greenSortList = new ArrayList<Map.Entry<String, Double>>(getGreenMap().entrySet());
			Collections.sort(greenSortList, new Comparator<Map.Entry<String, Double>>() {
				public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) {
					return (int) (o2.getValue() - o1.getValue());
				}
			});
		}
		return greenSortList;
	}

	public int getRedSumQty() {
		return redSumQty;
	}

	public void setRedSumQty(int redSumQty) {
		this.redSumQty = redSumQty;
	}

	public int getGreenSumQty() {
		return greenSumQty;
	}

	public void setGreenSumQty(int greenSumQty) {
		this.greenSumQty = greenSumQty;
	}

	public boolean isRgCategory() {
		return rgCategory;
	}

	public void setRgCategory(boolean rgCategory) {
		this.rgCategory = rgCategory;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "ApplyCampaign [isActive=" + isActive + ", sumDiscount=" + sumDiscount + ", sumPrice=" + sumAmount
				+ ", sumQty=" + sumQty + ", applyProductIds=" + applyProductIds + ", campaign="
				+ (campaign == null ? null : campaign.getUuid() + campaign.getCampaignName()) + "]";
	}

}
